<template>
	<view class="flex_a">
		<view class="battery green" :class="['battery',{green:quantity>80},{orange:quantity>=50 && quantity<79},{red:quantity<49}]">
			<view class="percent" :style="'width:'+quantity+'%'"></view>
		</view>
		<text class="ml10" v-if="electric===''">未记录</text>
		<text class="ml10" v-else>{{quantity}}%</text>
	</view>
</template>

<script>
	export default {
		name: "index",
		props: {
			electric: {
				type: String,
				default: '0'
			},
		},
		data() {
			return {

			}
		},
		computed: {
			quantity() {
				return this.electric*1>100?100:this.electric * 1;
			}
		},
		methods: {

		}
	}
</script>

<style scoped lang='scss'>
	.battery {
		position: relative;
		width: 50upx;
		height: 28upx;
		border: 2px solid #10a417;
		border-radius: 4upx;
		padding: 1px;
		box-sizing: border-box;

		&::after {
			content: '';
			position: absolute;
			width: 4px;
			height: 16upx;
			background-color: #10a417;
			top: 50%;
			margin-top: -8upx;
			right: -4px;
			border-radius: 0 2px 2px 0;
		}

		.percent {
			width: 0%;
			height: 100%;
		}

		&.green {
			border-color: #10a417;

			&::after {
				background-color: #10a417;
			}

			.percent {
				background-color: #10a417;
			}
		}

		&.orange {
			border-color: #f07625;

			&::after {
				background-color: #f07625;
			}

			.percent {
				background-color: #f07625;
			}
		}

		&.red {
			border-color: #ec2747;

			&::after {
				background-color: #ec2747;
			}

			.percent {
				background-color: #ec2747;
			}
		}
	}
</style>
